!function(){"use strict";angular.module("multi-select-tree",[])}(),function(){"use strict";var a=angular.module("multi-select-tree");a.controller("multiSelectTreeCtrl",["$scope","$document",function(a,b){function c(){d(),a.$apply()}function d(){a.showTree=!1,g&&(g.isActive=!1,g=void 0),b.off("click",c)}function e(b){for(var c=0,d=b.length;d>c;c++)f(b[c])||b[c].selected!==!0?f(b[c])&&b[c].selected===!1&&(b[c].selected=!0):a.selectedItems.push(b[c]),b[c]&&b[c].children&&e(b[c].children)}function f(b){var c=!1;if(a.selectedItems)for(var d=0;d<a.selectedItems.length;d++)if(a.selectedItems[d].id===b.id){c=!0;break}return c}var g;a.showTree=!1,a.selectedItems=[],a.multiSelect=a.multiSelect||!1,a.onActiveItem=function(a){g!==a&&(g&&(g.isActive=!1),g=a,g.isActive=!0)},a.refreshOutputModel=function(){a.outputModel=angular.copy(a.selectedItems)},a.refreshSelectedItems=function(){a.selectedItems=[],a.inputModel&&e(a.inputModel)},a.deselectItem=function(b,c){c.stopPropagation(),a.selectedItems.splice(a.selectedItems.indexOf(b),1),b.selected=!1,this.refreshOutputModel()},a.onControlClicked=function(d){d.stopPropagation(),a.showTree=!a.showTree,a.showTree&&b.on("click",c)},a.onFilterClicked=function(a){a.stopPropagation()},a.clearFilter=function(b){b.stopPropagation(),a.filterKeyword=""},a.canSelectItem=function(b){return a.callback({item:b,selectedItems:a.selectedItems})},a.switchCurrentView=function(b){b.stopPropagation(),a.switchViewCallback({scopeObj:a})},a.itemSelected=function(b){if(!(a.useCallback&&a.canSelectItem(b)===!1||a.selectOnlyLeafs&&b.children&&b.children.length>0)){if(a.multiSelect){b.selected=!0;var c=a.selectedItems.indexOf(b);f(b)?(b.selected=!1,a.selectedItems.splice(c,1)):a.selectedItems.push(b)}else{d();for(var e=0;e<a.selectedItems.length;e++)a.selectedItems[e].selected=!1;b.selected=!0,a.selectedItems=[],a.selectedItems.push(b)}this.refreshOutputModel()}}}]),a.directive("multiSelectTree",function(){return{restrict:"E",templateUrl:"src/multi-select-tree.tpl.html",scope:{inputModel:"=",outputModel:"=?",multiSelect:"=?",switchView:"=?",switchViewLabel:"@",switchViewCallback:"&",selectOnlyLeafs:"=?",callback:"&",defaultLabel:"@"},link:function(a,b,c){function d(a,b){for(var c=e(a,[]),d=0,f=c.length;f>d;d++)if(-1!==c[d].name.toLowerCase().indexOf(b.toLowerCase()))return!1;return!0}function e(a,b){for(var c=0;c<a.children.length;c++)b.push(a.children[c]),e(a.children[c],b);return b}c.callback&&(a.useCallback=!0),a.$watch("inputModel",function(b){b&&(a.refreshSelectedItems(),a.refreshOutputModel())}),a.$watch("filterKeyword",function(){void 0!==a.filterKeyword&&angular.forEach(a.inputModel,function(b){b.isFiltered=-1!==b.name.toLowerCase().indexOf(a.filterKeyword.toLowerCase())?!1:d(b,a.filterKeyword)?!0:!1})})},controller:"multiSelectTreeCtrl"}})}(),function(){"use strict";var a=angular.module("multi-select-tree");a.controller("treeItemCtrl",["$scope",function(a){a.item.isExpanded=!1,a.showExpand=function(a){return a.children&&a.children.length>0},a.onExpandClicked=function(a,b){b.stopPropagation(),a.isExpanded=!a.isExpanded},a.clickSelectItem=function(b,c){c.stopPropagation(),a.itemSelected&&a.itemSelected({item:b})},a.subItemSelected=function(b){a.itemSelected&&a.itemSelected({item:b})},a.activeSubItem=function(b){a.onActiveItem&&a.onActiveItem({item:b})},a.onMouseOver=function(b,c){c.stopPropagation(),a.onActiveItem&&a.onActiveItem({item:b})},a.showCheckbox=function(){return a.multiSelect?a.selectOnlyLeafs?!1:a.useCallback?a.canSelectItem(a.item):void 0:!1}}]),a.directive("treeItem",["$compile",function(a){return{restrict:"E",templateUrl:"src/tree-item.tpl.html",scope:{item:"=",itemSelected:"&",onActiveItem:"&",multiSelect:"=?",selectOnlyLeafs:"=?",isActive:"=",useCallback:"=",canSelectItem:"="},controller:"treeItemCtrl",compile:function(b,c,d){angular.isFunction(d)&&(d={post:d});var e,f=b.contents().remove();return{pre:d&&d.pre?d.pre:null,post:function(b,c){e||(e=a(f)),e(b,function(a){c.append(a)}),d&&d.post&&d.post.apply(null,arguments)}}}}}])}();